# common
import sys
import os
import os.path as op
# basic
import numpy as np
import pandas as pd
import xarray as xr
from scipy.io import loadmat
from time import time
import warnings
warnings.simplefilter('ignore')
# custom
from lib import calval
# functions
from lib import functions
# initial time to see the duration of the notebook
t0 = time()
# data
p_data = op.join(os.getcwd(), 'data')
buoy = pd.read_pickle(op.join(p_data, 'Bilbao-Vizcaya Ext.pkl'))
csiro = pd.read_pickle(op.join(p_data, 'csiro_dataframe.pkl'))
satellite = xr.open_dataset(op.join(p_data, 'satellite_dataset.nc'))
bat_spain = np.loadtxt(op.join(p_data, 'SPAIN_2020_bath.dat'))
bat_gebco = xr.open_dataset(op.join(p_data, 'GEBCO_2019_bath.nc'))
print('---------------------------------------------------')
print('Time wasted reading the data: ' + str(round(time()-t0, 2)) + ' s')
print('---------------------------------------------------')
t1 = time()
# creation of the main object
#######################################################
### VALUES WILL HAVE TO BE INSERTED SO BE READY ###
### Satellite box : South = 43.8 ###
### North = 44.2 ###
### West = 356.2 ###
### East = 356.6 ###
### Time calibration: False ###
### Threshold : 0.015 ###
#######################################################
# the Threshold allows us to delete not relevant information
calval_case = calval.CalVal(buoy, csiro, satellite, 'CSIRO', bat_spain, bat_gebco)
print('---------------------------------------------------')
print('Time wasted initializing the constructor: ' + str(round((time()-t1)/60, 2)) + ' m')
print('---------------------------------------------------')
t1 = time()
calval_case.hindcast_sat_corr.to_pickle(op.join(p_data, 'csiro_dataframe_sat_corr.pkl'))
calval_case.hindcast_buoy_corr.to_pickle(op.join(p_data, 'csiro_dataframe_buoy_corr.pkl'))
# comparisons
#######################################################
### VALUES WILL HAVE TO BE INSERTED SO BE READY ###
### Number of years : 2 ###
### Years : 2006 2007 ###
#######################################################
calval_case.buoy_comparison('raw')
calval_case.buoy_comparison('sat_corr')
calval_case.buoy_comparison('buoy_corr')
print('---------------------------------------------------')
print('Time wasted comparing: ' + str(round((time()-t1)/60, 2)) + ' m')
print('---------------------------------------------------')
t1 = time()
# validations
calval_case.buoy_validation('raw')
calval_case.buoy_validation('sat_corr')
calval_case.buoy_validation('buoy_corr')
print('---------------------------------------------------')
print('Time wasted comparing: ' + str(round((time()-t1)/60, 2)) + ' m')
print('---------------------------------------------------')
t1 = time()
# map
#######################################################
### VALUES WILL HAVE TO BE INSERTED SO BE READY ###
### Map box : South = 43.0 ###
### North = 44.4 ###
### West = -4.6 ###
### East = -2.4 ###
### Map parameters : grid_step = 0.2 ###
### depth = 300 ###
### Hindcast box : Longitude = -3.6 ###
### Latitude = 44.0 ###
#######################################################
calval_case.region_map()
print('---------------------------------------------------')
print('Time wasted plotting the map: ' + str(round((time()-t1)/60, 2)) + ' m')
print('---------------------------------------------------')
print('---------------------------------------------------')
print('TOTAL time of the script: ' + str(round((time()-t0)/60, 2)) + ' m')
print('---------------------------------------------------')